//
//  PaymentViewController.m
//  yigou
//
//  Created by 秦乾龙 on 17/1/11.
//  Copyright © 2017年 hanyiwang. All rights reserved.
//

#import "PaymentViewController.h"
#import "NavView.h"
@interface PaymentViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,retain) UITableView *mainTableView;
@property (nonatomic,retain) NavView *nav;
@property (nonatomic,retain) NSString *payMent;
@property (nonatomic,retain) NSString *payId;
@property (nonatomic,retain) NSArray *titleArr;
@property (nonatomic,retain) NSMutableArray *contentArr;

@end

@implementation PaymentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setUI];
    [self request];
}
- (void)setUI
{
    self.navigationItem.titleView = [ViewFactory makeNavigationTitle:@"收款方式"];
    
    UIBarButtonItem *backBtn = [ViewFactory makeNavigationBackWhite:self action:@selector(backClick)];
    self.navigationItem.leftBarButtonItem = backBtn;

    _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,ScreenW , ScreenH-64) style:UITableViewStyleGrouped];
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    [self.view addSubview:_mainTableView];
}
- (void)request
{
    DYBaseRequest *request = [DYBaseRequest new];
    request.requestUrl = [NSString stringWithFormat:@"%@/product/showPayType",APIYIGOU];
    [request dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
        _payMent = allDic[@"data"][2][@"value"];
        _payId = allDic [@"data"][2][@"id"];
        _contentArr = [NSMutableArray arrayWithObjects:_payMent,_payId, nil];
        [_mainTableView reloadData];
    } error:^(YTKBaseRequest *request) {
        
    } failure:^(YTKBaseRequest *request) {
        [ViewFactory showErrorStrMsg: NETWORK_ERR];
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell =[[NSBundle mainBundle ]loadNibNamed:@"ZYTableViewCell" owner:nil options:nil][0];
    }
    //设置cell点击背景色不变
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    NSArray *titleArr = [[NSArray alloc]initWithObjects:@"收款方式",@"银行卡号", nil];
    
    UILabel *titleLable = [[UILabel alloc]init];
    //        titleImage.backgroundColor = [UIColor cyanColor];
    titleLable.frame = CGRectMake(30*kScale, (100-44)*kScale/2, ScreenW, 44*kScale);
    titleLable.text = titleArr[indexPath.row];
    [cell addSubview:titleLable];
    UILabel *contentLable = [[UILabel alloc]init];
    if (_contentArr.count>1) {
        
        contentLable.frame  = CGRectMake(0, 0, ScreenW-30*kScale, 100*kScale);
//        contentLable.backgroundColor = [UIColor redColor];
        contentLable.text = _contentArr[indexPath.row];
        contentLable.textAlignment = NSTextAlignmentRight;
        contentLable.textColor = ZallColorFromRGB(0x9A9595);
        

    }
    [cell addSubview:contentLable];
    return cell;
}

- (void)cancleSelect
{
    [_mainTableView deselectRowAtIndexPath:[_mainTableView indexPathForSelectedRow] animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return  100*kScale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}
//修改状态栏字体
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}
- (void)backClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
